@dir=('BRCA','BLCA','COAD','KIRC','LAML','LGG','LUAD','PRAD','READ','LUSC','OV','GBM');
#@dir=('BRCA','LUSC','OV','GBM');
#@dir=('BRCA');
#for($in=0;$in<@dir;$in++)
for($in=2;$in<@dir;$in++)
{
	print "processing normal $dir[$in]\n";
	$dir=$dir[$in];
	$sys ="perl /data4/bsi/RandD/Workflow/genotyping_QC_FWD/perl_update_phasing_tar_file.pl /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir NORMAL";
	print $sys."\n";
	system($sys);
	#die;
=head
	$sys="perl /data4/bsi/RandD/Workflow/genotyping_QC_FWD/perl_fill_missing_genderinfo.pl /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/TCGA_Subject_Gender_Info.txt  /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/NORMAL/fwdStrandResults_all_merged_removeddup_normal_build37.tfam /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/NORMAL/test.tfam /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/NORMAL/samples_remove_noGender";
	print $sys."\n";
	system($sys);
	system("mkdir /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/NORMAL/new_update_gender");
	$count =`wc -l /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/NORMAL/samples_remove_noGender`;
	chomp($count);
	$count =~ s/ .+//g;
	#die "$count\n";
	if($count > 0)
	{
		$sys = "gunzip -c /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/NORMAL/fwdStrandResults_all_merged_removeddup_normal_build37.tped.gz > /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/NORMAL/test.tped ";
		print $sys."\n";
		system($sys);
		$sys = "plink --tfile /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/NORMAL/test --remove /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/NORMAL/samples_remove_noGender --transpose --recode --out /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/NORMAL/new_update_gender/fwdStrandResults_all_merged_removeddup_normal_build37";
		print $sys."\n";
		system($sys);
	}
	else
	{
		system("mv /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/NORMAL/test.tfam /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/NORMAL/new_update_gender/fwdStrandResults_all_merged_removeddup_normal_build37.tfam");
		system("cp /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/NORMAL/fwdStrandResults_all_merged_removeddup_normal_build37.tped.gz /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/NORMAL/new_update_gender/fwdStrandResults_all_merged_removeddup_normal_build37.tped.gz");
	}
	$verify=`cut -f5 -d ' ' /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/NORMAL/new_update_gender/fwdStrandResults_all_merged_removeddup_normal_build37.tfam|sort|uniq`;
	@verify=split("\n",$verify);
	#die "@verify\n";
	for($i=0;$i<@verify;$i++)
	{	
		if($verify[$i] !~ /\d/)
		{
			die "verify not a number $verfiy[$i]\n";
		}
	}
system("gzip  /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/NORMAL/new_update_gender/fwdStrandResults_all_merged_removeddup_normal_build37.tped");
#system("mkdir /data4/bsi/bioinf_ext1/s112349.ucsf/new_request_aug_20_2012/TCGA/$dir");
	open(WRBUFF,">/data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/runsh_it_$dir") or die " no file exists runshapeit\n";
	print WRBUFF '#! /bin/bash'."\n";
	print WRBUFF '#$ -q 1-day'."\n";
	print WRBUFF '#$ -l h_vmem=10G'."\n";
	print WRBUFF '#$ -M naresh.prodduturi@mayo.edu'."\n";
	print WRBUFF '#$ -m a'."\n";
	print WRBUFF '#$ -V'."\n";
	print WRBUFF '#$ -cwd'."\n";
	$sys="perl /data4/bsi/RandD/Workflow/genotyping_QC_FWD/perl_upgrade_build36_files.pl /data4/bsi/RandD/Workflow/genotyping_1000genome_impute/complete1KGSNPS_split/  /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/NORMAL/fwdStrandResults_all_merged_removeddup_normal.tped /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/NORMAL/fwdStrandResults_all_merged_removeddup_normal_build37.tped /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/NORMAL/fwdStrandResults_all_merged_removeddup_normal_build36.tped";
	print WRBUFF $sys."\n";
	$sys="cp /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/NORMAL/fwdStrandResults_all_merged_removeddup_normal.tfam /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/NORMAL/fwdStrandResults_all_merged_removeddup_normal_build37.tfam";
	#print WRBUFF $sys."\n";
	system($sys);
	$sys="/data4/bsi/RandD/Workflow/genotyping_QC_FWD/bin/plink/plink --tfile /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/NORMAL/fwdStrandResults_all_merged_removeddup_normal_build37 --maf 0.00001 --transpose --recode --out /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/NORMAL/fwdStrandResults_all_merged_removeddup_normal_build37_nomaf";
	print WRBUFF $sys."\n";
	$sys="mv /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/NORMAL/fwdStrandResults_all_merged_removeddup_normal_build37_nomaf.tped /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/NORMAL/fwdStrandResults_all_merged_removeddup_normal_build37.tped";
	print WRBUFF $sys."\n";
	$sys="mv /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/NORMAL/fwdStrandResults_all_merged_removeddup_normal_build37_nomaf.tfam /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/NORMAL/fwdStrandResults_all_merged_removeddup_normal_build37.tfam";
        print WRBUFF $sys."\n";
	$sys="gzip /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/NORMAL/fwdStrandResults_all_merged_removeddup_normal_build37.tped";
	print WRBUFF $sys."\n";
=cut
	#die;	
	if($dir ne "LAML")
	{
		print "processing tumor $dir\n";
		system("perl /data4/bsi/RandD/Workflow/genotyping_QC_FWD/perl_update_phasing_tar_file.pl /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir TUMOR");
=head
        $sys="perl /data4/bsi/RandD/Workflow/genotyping_QC_FWD/perl_fill_missing_genderinfo.pl /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/TCGA_Subject_Gender_Info.txt  /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/TUMOR/fwdStrandResults_all_merged_removeddup_tumor_build37.tfam /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/TUMOR/test.tfam /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/TUMOR/samples_remove_noGender";
		print $sys."\n";
		system($sys);
		system("mkdir /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/TUMOR/new_update_gender");
		$count =`wc -l /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/TUMOR/samples_remove_noGender`;
		chomp($count);
		$count =~ s/ .+//g;
		#die "$count\n";
		if($count > 0)
		{
			$sys = "gunzip -c /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/TUMOR/fwdStrandResults_all_merged_removeddup_tumor_build37.tped.gz > /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/TUMOR/test.tped ";
			print $sys."\n";
			system($sys);
			$sys = "plink --tfile /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/TUMOR/test --remove /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/TUMOR/samples_remove_noGender --transpose --recode --out /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/TUMOR/new_update_gender/fwdStrandResults_all_merged_removeddup_tumor_build37";
			print $sys."\n";
			system($sys);
		}
		else
		{
			system("mv /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/TUMOR/test.tfam /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/TUMOR/new_update_gender/fwdStrandResults_all_merged_removeddup_tumor_build37.tfam");
			system("cp /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/TUMOR/fwdStrandResults_all_merged_removeddup_tumor_build37.tped.gz /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/TUMOR/new_update_gender/fwdStrandResults_all_merged_removeddup_tumor_build37.tped.gz");
		}
		$verify=`cut -f5 -d ' ' /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/TUMOR/new_update_gender/fwdStrandResults_all_merged_removeddup_tumor_build37.tfam|sort|uniq`;
		@verify=split("\n",$verify);
		#die "@verify\n";
		for($i=0;$i<@verify;$i++)
		{	
			if($verify[$i] !~ /\d/)
			{
				die "verify not a number $verfiy[$i]\n";
			}
		}
		#die;	
system("gzip /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/TUMOR/new_update_gender/fwdStrandResults_all_merged_removeddup_tumor_build37.tped");	
		$sys="perl /data4/bsi/RandD/Workflow/genotyping_QC_FWD/perl_upgrade_build36_files.pl /data4/bsi/RandD/Workflow/genotyping_1000genome_impute/complete1KGSNPS_split/  /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/TUMOR/fwdStrandResults_all_merged_removeddup_tumor.tped /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/TUMOR/fwdStrandResults_all_merged_removeddup_tumor_build37.tped /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/TUMOR/fwdStrandResults_all_merged_removeddup_tumor_build36.tped";
        	print WRBUFF $sys."\n";
        $sys="cp /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/TUMOR/fwdStrandResults_all_merged_removeddup_tumor.tfam /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/TUMOR/fwdStrandResults_all_merged_removeddup_tumor_build37.tfam";
        print WRBUFF $sys."\n";
        system($sys);
        $sys="/data4/bsi/RandD/Workflow/genotyping_QC_FWD/bin/plink/plink --tfile /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/TUMOR/fwdStrandResults_all_merged_removeddup_tumor_build37 --maf 0.00001 --transpose --recode --out /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/TUMOR/fwdStrandResults_all_merged_removeddup_tumor_build37_nomaf";
        print WRBUFF $sys."\n";
        $sys="mv /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/TUMOR/fwdStrandResults_all_merged_removeddup_tumor_build37_nomaf.tped /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/TUMOR/fwdStrandResults_all_merged_removeddup_tumor_build37.tped";
        print WRBUFF $sys."\n";
        $sys="mv /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/TUMOR/fwdStrandResults_all_merged_removeddup_tumor_build37_nomaf.tfam /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/TUMOR/fwdStrandResults_all_merged_removeddup_tumor_build37.tfam";
        print WRBUFF $sys."\n";
        $sys="gzip /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/TUMOR/fwdStrandResults_all_merged_removeddup_tumor_build37.tped";
        print WRBUFF $sys."\n";
=cut
       
	}
#	system("qsub /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/runsh_it_$dir");

}
